<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<link rel="stylesheet" href="resours/css/style.css">
<title>Insert title here</title>
</head>
<body>
<div class="whole">
   <div class="login">
    <div class="title">Please Enter Your Password</div></br>
    <form id="form1" action="/tologin" method="post" class="form_box">
        <div class="input_tit">角色</div>
        <div class="input_box">
            <input class="input_self" type="text" name="flag" id="flag" />
        </div></br>
        <div class='blank_30'></div>
        <div class="input_tit">Your name</div>
        <div class="input_box">
            <input class="input_self" type="text" name="name" id="name" />
        </div></br>
        <div class='blank_30'></div>
        <div class="input_tit">Password</div>
        <div class="input_box">
            <input class="input_self" type="text" name="password" id="password" />
        </div></br>
        <div class="finish_box">
            <input class="finish_btn" type="button" id="finish" name="登录" value="登录" onclick="get()"/>
        </div>
    </form>
    </div>
  </div>
</body>
<script>
function get(){
	// ajax ---》 利用ajax进行数据提交  // ++ http协议
	var url = "http://localhost:8080/qcbycoursehelper/LoginServlet"; 
	var data = {
			"name":$("#name").val(),
			"password":$("#password").val(),
			"flag":$("#flag").val()
	}
	$.ajax({
        type:"post",//指定提交的类型，get对应doget(),post对应dopost()
        url: url,   // 地址
        data:data,//data代表key -value类型的数据  
        dataType:'JSON', //定义数据的类型
        success: function (value)//success、error代表是否返回成功
        {
        	console.log(value);
        	 if(value.message=="管理员查询成功"){
        		window.location.href="http://localhost:8080/qcbycoursehelper/admin.html"
        	}else if(value.message=="老师查询成功"){
        		window.location.href="http://localhost:8080/qcbycoursehelper/teacher.html"
        	}else if(value.message=="学生查询成功"){
        		window.location.href="http://localhost:8080/qcbycoursehelper/student.html"
        	} 
        },
        error:function (XMLHttpRequest, textStatus, errorThrown) { 
            alert(typeof(errorThrown));
        }
     });
}

</script>
</html>